// 
var findNumberIn2DArray = function (matrix, target) {
  // 暴力算法
  // for (var i of matrix) {
  //   for (var j of i) {
  //     if (j > target) break
  //     if (j == target) return true
  //   }
  // }
  // return false
  let i = matrix.length - 1
  let j = 0
  while (j < matrix[0].length && i >= 0) {
    if (matrix[i][j] > target) {
      i--
    } else if (matrix[i][j] < target) {
      j++
    } else return true
  }
  return false
};
let matrix = [
  [1, 4, 7, 11, 15],
  [2, 5, 8, 12, 19],
  [3, 6, 9, 16, 22],
  [10, 13, 14, 17, 24],
  [18, 21, 23, 26, 30]
]
console.log(findNumberIn2DArray(matrix, 5));